package com.example.prgraphview1;

import android.graphics.Color;

import com.androidplot.series.XYSeries;
import com.androidplot.xy.LineAndPointFormatter;
import com.androidplot.xy.PointLabelFormatter;
import com.androidplot.xy.SimpleXYSeries;
import com.androidplot.xy.XYPlot;

import java.util.Arrays;

/**
 * Created by esalazar on 7/11/13.
 */
public class AndroidPlotGraphicMaker implements GraphicMaker {

    XYPlot plot;

    public AndroidPlotGraphicMaker(XYPlot plot) {
        this.plot = plot;

    }
    @Override
    public void paint() {
        plot.setVisibility(1);
        // Create a couple arrays of y-values to plot:
        Number[] series1Numbers = {1, 2, 4, 9, 16, 25};
        Number[] series2Numbers = {4, 6, 3, 8, 2, 10};

        // Turn the above arrays into XYSeries':
        XYSeries series1 = new SimpleXYSeries(
                Arrays.asList(series1Numbers),          // SimpleXYSeries takes a List so turn our array into a List
                SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, // Y_VALS_ONLY means use the element index as the x value
                "Series1");                             // Set the display title of the series

        // same as above
        XYSeries series2 = new SimpleXYSeries(Arrays.asList(series2Numbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Series2");

        // Create a formatter to use for drawing a series using LineAndPointRenderer:
        final PointLabelFormatter pointLabelFormatter = new PointLabelFormatter(66);
        LineAndPointFormatter series1Format = new LineAndPointFormatter(
                Color.rgb(0, 200, 0),                   // line color
                Color.rgb(0, 100, 0),                   // point color
                null, pointLabelFormatter);                                  // fill color (none)

        // add a new series' to the xyplot:
        plot.addSeries(series1, series1Format);

        // same as above:
        plot.addSeries(series2,
                new LineAndPointFormatter(Color.rgb(0, 0, 200), Color.rgb(0, 0, 100), null,pointLabelFormatter));

        // reduce the number of range labels
        plot.setTicksPerRangeLabel(3);

        // by default, AndroidPlot displays developer guides to aid in laying out your plot.
        // To get rid of them call disableAllMarkup():
        plot.setMarkupEnabled(false);
    }
}
